// TreeModel.h: interface for tree model structures.
// Copyright: (c) Project 5 Team (715), 2009
//
// Last edited July 2012 by Zane Moser and Camille Nicodemus
//////////////////////////////////////////////////////////////////////

#ifndef TREEMODEL_CSKETCH
#define TREEMODEL_CSKETCH

#include "TreeMain.h"
#include "Sketch.h"
#include "Geometry.h"
//#include "GeometryFunctions.h"
#include "TreeTextureLoader.h"

#include <math.h>
#include <string>
#include <vector>

#ifdef WIN32
#include <time.h>
#include <windows.h>
#include <GL/gl.h>

#else
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif

namespace LifeSketchTree
{
class CNode2D 
{
public:
	CNode2D(CSketch* l, bool f); // root2D constructor
	CNode2D(CNode2D* p, int pi, CSketch* l, bool f, bool isTwig);
	CNode2D(CNode2D* p, CSketch* l, CVec2di* StartPoint, CVec2di* axisPoint, bool isTwig, bool isLeft);
	~CNode2D();
	
	void setLine(CSketch* sketch);
	void addChild(CNode2D* child);
	vector<CNode2D*>* getChildren();
	int depth();
	CNode2D* getParent();
	//int getParentIntersection();
	CSketch* getLine();
	bool isForwards();
	bool isLeft();
	
	bool isTwig();
	
	CVec2di* getStartPoint();
	CVec2di* getAxisPoint();
	
private:
	bool left;
	bool twig;
	CNode2D* parent;
	//int parentIntersection;
	CSketch* line;
	bool forwards;
	CVec2di* StartPoint;
	CVec2di* axisPoint;
	
	vector<CNode2D*> children;
};

//////////////////////////////////////////////////////////////////////

class CNode3D 
{
public:
	CNode3D(vector<CVec3df*>* l);
	CNode3D(CNode3D* p, vector<CVec3df*>* l, bool isLeft, bool isTwig);
	~CNode3D();
	
	void setLine(vector<CVec3df*>* line);
	void addChild(CNode3D* child);
	void setAngle(double angle);
	void setLeft(bool isLeft);
	bool isLeft();
	bool isCopy();
	bool isTwig();
	void setTwig(bool t);
	void setCopy(bool c);
	double angleOfBranch();
	
	CNode3D* copyNode();
	
	vector<CNode3D*>* getChildren();
	void setParent(CNode3D* p);
	CNode3D* getParent();
	//void setParentIntersection(int i);
	int getParentIntersection();
	vector<CVec3df*>* getLine();
	int depth();
	CVec3df* getAxisPoint();
	void setAxisPoint(CVec3df* point);
	
private:
	void rotateAroundAxis(CVec3df axis1,CVec3df axis2, double r);
	CNode3D* parent;
	//int parentIntersection;
	vector<CVec3df*>* line;
	vector<CNode3D*> children;
	CVec3df* axisPoint; // point before this is the other axis
	bool copy;
	double angle;
	bool left;
	bool twig;
};

double lineAngle(CVec2di* p1, CVec2di* p2);
double lineAngle3D(CVec3df* p1, CVec3df* p2);

//////////////////////////////////////////////////////////////////////
}
#endif